<?php
// 主入口
class IndexAction extends CommonAction {
	public function _before_index(){
		//输出日期
		$username=$_SESSION ['username'];
		$wk_day=date("w"); //得到星期几 0-6
		$wkday_ar=array("日","一","二","三","四","五","六"); //规范化周日的表达
		$str=date("Y年n月j日")."，星期".$wkday_ar[$wk_day];
		$this->assign('datestr',$str);
		//查询公告信息
		$notice=M('Notice');
		$noticeInfo=$notice->where('istrend=0 and status=1')->order('rank desc')->limit(5)->select();
		$trendInfo=$notice->where('istrend=1 and status=1')->order('pubdate desc')->limit(5)->select();
		$this->assign('noticeInfo',$noticeInfo);
		$this->assign('trendInfo',$trendInfo);
		//查询我的消息，按照发送时间降序排列
		$shortmessage=M('ShortMessage');
		$message=$shortmessage->where("receivername='".$username."' and deleted=0")->order('sendtime desc')->limit(5)->select();
		$messagecount=$shortmessage->where("receivername='".$username."'")->count();
		$this->assign('message',$message);
		$this->assign('messagecount',$messagecount);
		//查找合同中未审批的记录，按照签约时间排列
		$contract=M('Contract');
		$contractlist=$contract->where('status=101 and removed=1')->order('signuptime desc')->limit(6)->select();
		$contractcount=$contract->where('status=101 and removed=1')->count();
		$this->assign('contractlist',$contractlist);
		//查找借款中未审批的记录
		$borrow=M('Brrow');
		$borrowlist=$borrow->where('appstat=0')->order('btime desc')->limit(5)->select();
		$borrowcount=$borrow->where('appstat=0')->count();
		$this->assign('borrowlist',$borrowlist);
		//总的未审批的条数
		$this->assign('approvecount',$contractcount+$borrowcount);
	
		
		//查看车辆日志信息
		$carlog=M('CarLog');
		$carlist=$carlog->limit(6)->select();
		$this->assign('carlist',$carlist);
		
	}
	public function index() {
		$this->assign ( 'title', 'OA后台系统' );
		if (isset ( $_SESSION [C ( 'USER_AUTH_KEY' )] )) {
			// 显示菜单项
			$menu = array ();
			
			// 读取数据库模块列表生成菜单项
			$node = M ( "Node" );
			$id = $node->getField ( "id" );
			$where ['level'] = 2;
			$where ['status'] = 1;
			$where ['pid'] = $id;
			$list = $node->where ( $where )->field ( 'id,name,group_id,title' )->order ( 'sort asc' )->select ();
			$accessList = $_SESSION ['_ACCESS_LIST'];
			foreach ( $list as $key => $module ) {
				if (isset ( $accessList [strtoupper ( APP_NAME )] [strtoupper ( $module ['name'] )] ) || $_SESSION ['administrator']) {
					// 设置模块访问权限
					$module ['access'] = 1;
					$menu [$key] = $module;
				}
			}
			
			if (! empty ( $_GET ['tag'] )) {
				$this->assign ( 'menuTag', $_GET ['tag'] );
			}
			// dump($menu);
			$this->assign ( 'menu', $menu );
		}
		C ( 'SHOW_RUN_TIME', false ); // 运行时间显示
		C ( 'SHOW_PAGE_TRACE', false );
		$this->display ();
	}
}